﻿@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.Common.Enums
@{
    var isProcessing = Request["IsProcessing"] ?? "false";
    ViewBag.Title = isProcessing.Equals("true", StringComparison.InvariantCultureIgnoreCase) ? "跟进中的任务" : "已处理任务";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord
<ul class="nav nav-tabs">
    <li class="active">
        <a href="/InsuranceWarrantyRecordDetail/InsuranceWarrantyRecord?IsProcessing=@isProcessing">
            @ViewBag.Title
        </a>
    </li>
</ul>
@using (Html.BeginForm("ExportInsuranceWarrantyRecordList", "InsuranceWarrantyRecordDetail", FormMethod.Post, new { id = "excelForm" }))
{
    @Html.Hidden("IsProcessing", isProcessing)
    <table>
        <tr>
            <td>保单号：</td>
            <td>
                @Html.TextBox("ThirdOrderNO", "", new { @class = "input-small" })
            </td>
            <td>报案人：</td>
            <td>@Html.TextBoxFor(m => m.Reporter, new { maxlength = 20, @class = "input-small" })</td>
            <td>报案人电话：</td>
            <td>@Html.TextBoxFor(m => m.ReporterPhone, new {maxlength = 20, @class = "input-small"})</td>
            <td>工单状态：</td>
            <td>

                @{
                    byte parentStatus = 0;
                    if (isProcessing == "true")
                    {
                        parentStatus = (byte)InsuranceWarrantyStatus.Processing;
                    }
                    else
                    {
                        parentStatus = (byte)InsuranceWarrantyStatus.Processed;
                    }
                }

                @Html.DropDownListFor(c => c.Status, ConvertToSelector.Instance.InsuranceWarrantyRecordStatusConvertToSelectList(parentStatus, null))

            </td>
        </tr>
        <tr>

            <td>被保险人：</td>
            <td>@Html.TextBox("UserName", "", new { maxlength = 15, @class = "input-small" })</td>
            <td>被保险人电话：</td>
            <td>@Html.TextBox("UserPhone", "", new { maxlength = 15, @class = "input-small" })</td>
            <td>证件号码：</td>
            <td>@Html.TextBox("CertificateNO", "", new { maxlength = 20, @class = "input-medium" })</td>
            <td>保险报案日期：</td>
            <td>
                @Html.TextBox("CreateTimeStart", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
                @Html.TextBox("CreateTimeEnd", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
            </td>
        </tr>
        <tr>
            <td>保险产品名称：</td>
            <td>
                @Html.TextBox("ProductName", "", new { maxlength = 20, @class = "input-small" })
            </td>
            <td>保险产品类型：</td>
            <td>
                <select id="InsuranceCategoryName" name="InsuranceCategoryName">
                    <option value="">请选择</option>
                    <option value="碎屏险">碎屏险</option>
                </select>
            </td>
            <td>设备识别码：</td>
            <td>@Html.TextBox("IMEI", "", new {maxlength = 20, @class = "input-medium"})</td>
            @if (Convert.ToBoolean(Request["IsProcessing"]))
            {
            <td>保险起期：</td>
            <td>
                @Html.TextBox("ServiceStartTime", "", new {@class = "Wdate input-small", onclick = "WdatePicker()"})
                @Html.TextBox("ServiceStartTime1", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
            </td>
            }
            else
            {
            <td>关单日期：</td>
            <td>
                @Html.TextBox("CloseOrderTimeStart", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
                @Html.TextBox("CloseOrderTimeEnd", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
            </td>
            }
        </tr>
        <tr>
            @if (Convert.ToBoolean(Request["IsProcessing"]))
            {
                <td>保险止期：</td>
                <td>
                    @Html.TextBox("ServiceEndTime", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
                    @Html.TextBox("ServiceEndTime1", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
                </td>
            }
            <td>销售商户：</td>
            <td>@Html.TextBox("SaleVendorName", "", new { maxlength = 20, @class = "input-small" })</td>
            <td colspan="6">
                <input id="btnSubmit" class="btn btn-primary Search-R margin-l-10" type="button" value="查询" onclick="search();" />
                <input id="btnSubmit" class="btn btn-primary Search-R margin-l-10" type="button" value="重置" onclick="reset();search();" />
                <!--已处理任务-->
                <input type="hidden" value="@Request["IsProcessing"]" id="IsProcessing" name="IsProcessing" />
                <input type="hidden" value="False" id="IsDownloadFile" name="IsDownloadFile" />
                <input type="hidden" value="" id="FileName" name="FileName" />
                @if (!Convert.ToBoolean(Request["IsProcessing"]))
                {
                    <input id="btnStayExport" class="btn btn-success Search-R margin-l-10" type="button" value="导出" />
                    <a id="GetFiles" onclick="getFile()" class="btn btn-primary Search-R margin-l-10" style="display:none;">获取文件</a>
                }
                else
                {
                    <input class="btn btn-success Search-R margin-l-10" type="submit" value="导出" />
                }

            </td>
        </tr>
    </table>
}
<div class="table-responsive dataTables_wrapper">
    <table id="insuranceWarrantyRecordList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th width="60">保单号</th>
                <th width="80">承保公司</th>
                <th>承保公司分公司</th>
                <th>报案人</th>
                <th>报案人电话</th>
                <th>被保险人</th>
                <th>被保险人电话</th>
                <th>保险产品类别</th>
                <th>保险产品名称</th>
                <th>销售商户</th>
                <th>创建时间</th>
                <th width="120">工单状态</th>
                @if (!Convert.ToBoolean(Request["IsProcessing"]))
                {
                    <th>关单时间</th>
                }
            </tr>
        </thead>
    </table>
</div>
<script src="~/Content/js/moment.js"></script>
@section scripts{
    <script type="text/javascript">
        window.onload = function() {           
            if (@(Request["IsProcessing"]).toString()=="false") {
                $("#Status").val("20"); //默认选中已完成服务
             var date_ = new Date();    
            var year = date_.getFullYear();    
            var month = date_.getMonth() + 1;    
            var firstdate = year + '-' + month + '-01';//当月第一天    
            var day = new Date(year,month,0);        
            var lastdate = year + '-' + month + '-' + day.getDate();//当月最后一天
            document.getElementById("CloseOrderTimeStart").value=firstdate.toString("yyyy-mm-dd");
            document.getElementById("CloseOrderTimeEnd").value=lastdate.toString("yyyy-mm-dd 23:59:59");
        }
        search();
        }

        function reset() {
            document.getElementById("excelForm").reset();
        }

        var zipFileName = "";
        $(function() {
            var objTable = $("#insuranceWarrantyRecordList")
                .dataTable({
                    fnDrawCallback: function() {
                        ControlPermissionOperate();
                    },
                    "aaSorting": [[11, "desc"]],
                    "sAjaxSource": "/InsuranceWarrantyRecordDetail/InsuranceWarrantyRecord?IsProcessing=@(isProcessing)",
                    aoColumns: [
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function(nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        {
                            "mData": null,
                            fnRender: function(nRow) {
                                return "<a class='Edit-R' href='/InsuranceWarrantyRecordDetail/Detail/" + nRow.aData.ID + "' title='查看详情'>" + nRow.aData.ThirdOrderNO + "</i></a>";
                            }
                        },
                        { "mData": "InsuranceCompany","bSortable": false },
                        { "mData": "InsuranceCompanyBranch","bSortable": false },
                        { "mData": "Reporter","bSortable": false },
                        { "mData": "ReporterPhone","bSortable": false },
                        { "mData": "UserName","bSortable": false },
                        { "mData": "UserPhone" ,"bSortable": false},
                        { "mData": "InsuranceCategoryName","bSortable": false },
                        { "mData": "ProductName","bSortable": false },
                        { "mData": "SaleVendorName","bSortable": false },
                        {
                            "mData": null,
                            fnRender: function(nRow) {
                                return moment(nRow.aData.CreateTime).format('YYYY-MM-DD HH:mm:ss');
                            }
                        },
                        { "mData": "StatusDesc","bSortable": false },
                        @(Request["IsProcessing"] == "false"?Html.Raw("{ 'mData': null, 'bSortable': false }"): Html.Raw(""))
                    ],
                    "fnRowCallback": function(nRow, aData, iDisplayIndex) {
                            var IsProcessing = @(Request["IsProcessing"]);
                            if (IsProcessing==false)
                            {
                                $('td:eq(13)', nRow).html(moment(aData.LastModifyTime).format('YYYY-MM-DD HH:mm:ss'));
                            }
                        }
                    });

            //导出excel
            $("#btnStayExport").on("click", function() {
                var isprocess = $("#IsProcessing").val()
                layer.confirm('确定要导出已处理任务清单吗？', {
                    btn: ['确认', '取消']
                }, function(index, layero) {
                    //已完成 需要导出资料
                    if (isprocess != "True") {
                        zipFileName = Date.parse(new Date());
                        layer.confirm('是否需要同步导出各项任务的附件资料？', {
                            btn: ['是', '否']
                        }, function(_index) {
                            layer.close(_index);
                            $("#GetFiles").show();
                            $("#IsDownloadFile").val("True");
                            $("#FileName").val(zipFileName);
                            document.getElementById("excelForm").submit();
                        }, function(_index) {
                            layer.close(_index);
                            $("#IsDownloadFile").val("False");
                            document.getElementById("excelForm").submit();
                        });
                    } else {
                        document.getElementById("excelForm").submit();
                    }

                }, function(index) {
                });
            });

        });

        //下载文件
        function getFile() {
            layer.confirm('确定要获取各项任务的附件资料吗？', {
                btn: ['确认', '取消']
            }, function(_index) {
                layer.close(_index);
                $.ajax({
                    url: '@Url.Action("DownloadFiles", "InsuranceWarrantyRecord")',
                    dataType: "json",
                    type: "POST",
                    data: { content: "/UploadFile/File/customerZipOrder/" + zipFileName + ".zip" },
                    async: false,
                    success: function(data) {
                        re = data.sucess;
                        if (data.sucess) {
                            //$("#GetFiles").attr("href", "/UploadFile/File/zipOrder/" + zipFileName + ".zip").attr("onclick", "").trigger("click");
                            window.location.href = "/UploadFile/File/customerZipOrder/" + zipFileName + ".zip"
                        } else {
                            layer.alert(data.message)
                        }
                    }
                });
            }, function(_index) {
                layer.close(_index);
            });

        }

        function search() {
            queryParamList.Reporter = $("#Reporter").val();
            queryParamList.ReporterPhone = $("#ReporterPhone").val();
            queryParamList.Status = $("#Status").val();
            queryParamList.ThirdOrderNO = $("#ThirdOrderNO").val().trim();
            queryParamList.UserPhone = $("#UserPhone").val();
            queryParamList.UserName = $("#UserName").val();
            queryParamList.CertificateNO = $("#CertificateNO").val();
            queryParamList.ServiceStartTime = $("#ServiceStartTime").val();
            queryParamList.ServiceStartTime1 = $("#ServiceStartTime1").val();
            queryParamList.ServiceEndTime = $("#ServiceEndTime").val();
            queryParamList.ServiceEndTime1 = $("#ServiceEndTime1").val();
            queryParamList.IMEI = $("#IMEI").val();
            queryParamList.InsuranceCategoryName = $("#InsuranceCategoryName").val();
            queryParamList.ProductName = $("#ProductName").val();
            queryParamList.SaleVendorName = $("#SaleVendorName").val();
            queryParamList.CreateTimeStart = $("#CreateTimeStart").val();
            queryParamList.CreateTimeEnd = $("#CreateTimeEnd").val();
            queryParamList.CloseOrderTimeStart = $("#CloseOrderTimeStart").val();
            queryParamList.CloseOrderTimeEnd = $("#CloseOrderTimeEnd").val();
            $("#insuranceWarrantyRecordList").dataTable().fnDraw();
        }
    </script>
}

